﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using ERP.Membership;

namespace ERP
{
    public partial class SiteMaster : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ERPMembership membership = new ERPMembership();
            var user = membership.GetCurrentLoggedInUser();
            
            
            
            
            if (user != null)
            {
                loginDisplay.InnerText = user.Email;
                if (user.Permissions.HasFlag(Permission.OrdersApprover))
                {
                    MenuItemAllOrders.Visible = true;
                }
                if (user.Permissions.HasFlag(Permission.OrdersWrite))
                {
                    MenuItemMyOrders.Visible = true;
                }
                if (user.Permissions.HasFlag(Permission.Admin))
                {
                    MenuItemStock.Visible = true;
                }
                if (user.Permissions.HasFlag(Permission.Admin))
                {
                    MenuItemAdmin.Visible = true;
                }
                
            }
        }

        protected void SetCulture(object sender, CommandEventArgs e)
        {
            Session["Culture"] = e.CommandArgument.ToString();
            Response.Redirect(Request.RawUrl);
        }

        protected void onclickLogOut(object sender, EventArgs e)
        {
            ERPMembership membership = new ERPMembership();
            membership.Logout();
            Response.Redirect("default.aspx");
        }

    }
}

